﻿using parkMonitor.viewModel.detail;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace parkMonitor.viewModel {
	/// <summary>启动号牌机窗口ViewModel</summary>
	public class StartNumMachineWinVM : INotifyPropertyChanged {
		//ip
		string _Ip = "";
		public string Ip {
			get { return _Ip; }
			set { _Ip = value; FirePropertyChanged("Ip"); }
		}

		//ip
		//int _port = 0;
		public int port {
			get {
				try {
					return Int32.Parse(StrPort);
				} catch(Exception) { }
				return 0;
			}
			set {
				if(value <= 0) {
					StrPort = "";
				} else {
					StrPort = value.ToString();
				}
				//Debug.WriteLine(value);
				FirePropertyChanged("port");
			}
		}
		string _StrPort = "";
		public string StrPort {
			get { return _StrPort; }
			set { _StrPort = value; FirePropertyChanged("StrPort"); }
		}

		//User Name
		string _UserName = "";
		public string UserName {
			get { return _UserName; }
			set { _UserName = value; FirePropertyChanged("UserName"); }
		}

		//Password
		//string _Password = "";
		//public string Password {
		//	get { return _Password; }
		//	set { _Password = value; FirePropertyChanged("Password"); }
		//}

		//命令日志
		string _CommanddLog = "";
		public string CommanddLog {
			get { return _CommanddLog; }
			set { _CommanddLog = value; FirePropertyChanged("CommanddLog"); }
		}

		//命令输入
		string _CommanddInput = "";
		public string CommanddInput {
			get { return _CommanddInput; }
			set { _CommanddInput = value; FirePropertyChanged("CommanddInput"); }
		}

		//设备列表
		ObservableCollection<DevListVM> _DevList = new ObservableCollection<DevListVM>();
		public ObservableCollection<DevListVM> DevList {
			get { return _DevList; }
			set { _DevList = value; FirePropertyChanged("DevList"); }
		}

		public virtual event PropertyChangedEventHandler PropertyChanged;
		public virtual void FirePropertyChanged(string propertyName) {
			if(PropertyChanged != null) {
				PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
			}
		}
		
		/// <summary>设备列表ViewModel</summary>
		public class DevListVM : INotifyPropertyChanged {
			//ip
			string _ip = "";
			public string ip {
				get { return _ip; }
				set { _ip = value; FirePropertyChanged("Data"); }
			}

			//ip
			int _port = 0;
			public int port {
				get { return _port; }
				set { _port = value; FirePropertyChanged("Data"); }
			}

			//Is Connect
			bool _IsConnected = false;
			public bool IsConnected {
				get { return _IsConnected; }
				set { _IsConnected = value; FirePropertyChanged("IsConnected"); }
			}

			//ip:port
			//string _Data = "";
			public string Data {
				get { return _ip + ":" + _port; }
				//set { FirePropertyChanged("Data"); }
			}

			//User Name
			string _UserName = "";
			public string UserName {
				get { return _UserName; }
				set { _UserName = value; FirePropertyChanged("UserName"); }
			}

			//Password
			string _Password = "";
			public string Password {
				get { return _Password; }
				set { _Password = value; FirePropertyChanged("Password"); }
			}

			public virtual event PropertyChangedEventHandler PropertyChanged;
			public virtual void FirePropertyChanged(string propertyName) {
				if(PropertyChanged != null) {
					PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
				}
			}
		}
	}

}
